<template >
<view class="container">

    <view  class="search">
        <navigator  hover-class="none" url="/pages/search/search" class="input">
            <img class="icon"/>
            <text class="txt">商品搜索, 共{{goodsCount}}款好物</text>
        </navigator>
    </view>
    <view class="catalog">
        <scroll-view class="nav" scroll-y="true">
            <view class="letYs"  :class='{ChooseLetYs:index==thisclick}' v-for="(item, index) of navList" :key="item.id" :data-id="item.id"
                :data-index="index"   @click="switchCate(index)">{{item.cateName}}</view>
        </scroll-view>
        <!-- :scroll-top="scrolltop" -->
        <!-- @scrolltolower="scrolltolower" -->
        <!-- scroll-with-animation="true" -->
        <scroll-view class="cate"    scroll-y="true"    >
          <!-- <view  v-for='(item,indx) in navList' :key='item.indx'> -->
              <!-- <view class="banner">
                <img class="image" src="/static/images/catalog1.png"/>
            </view> -->
            <div style="height:20px;"></div>
                  <view class="bd">
              <!-- :url="'/pages/category/category?id=' + item.id" -->
                <navigator  hover-class="none"   :class="(index+1) % 3 == 0 ? 'last item' : 'item'" v-for="(itemList, index) of  childList"
                    :key="itemList.index" :url="'/pages/search/search?keyword=' + itemList.cateName" >
            
                    <img class="icon" :src="itemList.cateImgUrl"/>
                    <text class="txt">{{itemList.cateName}}</text>
                </navigator>
            <!-- </view> -->



          </view>

            
        <div style="height:50px;"></div>
          
            
        </scroll-view>
    </view>
    
</view>
</template>

<script>
import api from '@/utils/api'

export default {
  data () {
    return {
      navList: [],
      categoryList: [],
      currentCategory: {},
      scrollLeft: 0,
      scrollTop: 0,
      goodsCount: 0,
      scrollHeight: 0,
      arrList:[],
      scrolltop:'0',
      chooseid:'',
      thisclick:0,
      childList:[]
    }
  },
  async mounted () {
    await Promise.all([
      this.getCurrentCategory()
    ])
  },
  methods: {
  
    // 分类主页数据和数量
    
      async getCurrentCategory () {
         let data=JSON.stringify({})
        const res = await api.CategoryList({"data":data});
        this.navList=res.data
        this.arrList=res.data;
        this.childList=this.navList[0].childList;
    },
    scrolltolower(){
      console.log('last')
    },
    
    scroll(e) {
      // console.log(6)
      // if(e.target.scrollTop<=435){
      //   this.thisclick=0;
      // }else if(e.target.scrollTop<1185){
      //     this.thisclick=parseInt((e.target.scrollTop-435)/327  )+1 

      // }else{
      //   this.thisclick=4;
      // }
      
      // console.log(e.target.scrollTop)
    },
    // 选择不同的分类
      switchCate (index) {
        this.thisclick=index;
        this.childList=this.navList[index].childList;
    // console.log(this.navList[index].childList)
    
     
    },
 
  },
  // 原生的分享功能？？
  onShareAppMessage: function () {
    return {
      title: 'dfcShop',
      desc: '大风车商场',
      path: '/pages/index/index'
    }
  },
    onPageScroll(e){//滚动监听
     console.log(e)
  },
}
</script>

<style lang='scss'>
page {
  height: 100%;
}

.container {
  background: #f9f9f9;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.letYs{
 text-align: center;
  line-height: 60px;;
  width: 162rpx;
  height: 60px;;
  color: #333;
  font-size: 15px;;
}
.ChooseLetYs{
  background: #fff;
  color:#FD6D1F;
}
.search {
  height: 88rpx;
  width:100vw;
 margin:0 auto;
  background: #fff;
  display: flex;
  align-items: center;
}

.search .input {
  width: 690rpx;
  height: 56rpx;
  background: #ededed;
  border-radius: 8rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 24rpx;
}

.search .icon {
  background: url(http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/search2-2fb94833aa.png) center no-repeat;
  background-size: 100%;
  width: 28rpx;
  height: 28rpx;
}

.search .txt {
  height: 42rpx;
  line-height: 42rpx;
  color: #666;
  padding-left: 10rpx;
  font-size: 30rpx;
}

.catalog {
  flex: 1;
  width: 100%;
  background: #fff;
  display: flex;
  border-top: 1px solid #fafafa;
}

.catalog .nav {
  width: 162rpx;
  height: 100%;;
  background: rgba(51,51,51,0.05);
}

.catalog .nav .item {
 
 
}

.catalog .nav .item.active {
  color: #333333;
  font-size: 36rpx;
 

 
}

.catalog .cate {
 
  flex: 1;
  height: 100%;
  padding: 0 15rpx 0 15rpx;
}

.banner {
  display: block;
  height: 222rpx;
  width: 100%;
  position: relative;
}

.banner .image {
  position: absolute;
  /* top: 30rpx; */
  left: 0;
  border-radius: 4rpx;
  height: 192rpx;
  width: 100%;
}

.banner .txt {
  position: absolute;
  top: 30rpx;
  text-align: center;
  color: #fff;
  font-size: 28rpx;
  left: 0;
  height: 192rpx;
  line-height: 192rpx;
  width: 100%;
}

.catalog .hd {
  height: 108rpx;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.catalog .hd .txt {
  font-size: 24rpx;
  text-align: center;
  color: #333;
  padding: 0 10rpx;
  width: auto;
}

.catalog .hd .line {
  width: 40rpx;
  height: 1px;
  background: #d9d9d9;
}

.catalog .bd {
  height: auto;
  width: 250px;
  margin: 0 auto;
  overflow: hidden;
}

.catalog .bd .item {
  display: block;
  float: left;
  height: 216rpx;
  width: 144rpx;
  margin-right: 34rpx;
}

.catalog .bd .item.last {
  margin-right: 0;
}

.catalog .bd .item .icon {
  height: 144rpx;
  width: 144rpx;
}

.catalog .bd .item .txt {
  display: block;
  text-align: center;
  font-size: 24rpx;
  color: #333;
  height: 72rpx;
  width: 144rpx;
}

</style>
